package lp.xian.equipment.service.impl;

import com.ruoyi.common.domain.Supplier;
import com.ruoyi.common.mapper.SupplierMapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;

import lp.xian.equipment.service.ISupplierService;
import lp.xian.equipment.vo.SupplierVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 供应商 Service业务层处理
 *
 * @author ruoyi
 * @date 2023-06-29
 */
@Service
public class SupplierServiceImpl implements ISupplierService
{
    @Autowired
    private SupplierMapper supplierMapper;

    /**
     * 查询供应商
     *
     * @param supplierId 供应商 主键
     * @return 供应商
     */
    @Override
    public Supplier selectSupplierBySupplierId(Integer supplierId)
    {
        return supplierMapper.selectSupplierBySupplierId(supplierId);
    }

    /**
     * 查询供应商 列表
     *
     * @param supplier 供应商
     * @return 供应商
     */
    @Override
    public List<Supplier> selectSupplierList(Supplier supplier)
    {
        return supplierMapper.selectSupplierList(supplier);
    }

    /**
     * 新增供应商
     *
     * @param supplier 供应商
     * @return 结果
     */
    @Override
    public int insertSupplier(Supplier supplier)
    {
        supplier.setCreateTime(DateUtils.getNowDate());
        supplier.setCreateBy(SecurityUtils.getUsername());//获取当前用户昵称
        return supplierMapper.insertSupplier(supplier);
    }

    /**
     * 修改供应商
     *
     * @param supplier 供应商
     * @return 结果
     */
    @Override
    public int updateSupplier(Supplier supplier)
    {
        supplier.setUpdateTime(DateUtils.getNowDate());
        supplier.setUpdateBy(SecurityUtils.getUsername());//获取当前用户昵称
        return supplierMapper.updateSupplier(supplier);
    }

    /**
     * 批量删除供应商
     *
     * @param supplierIds 需要删除的供应商 主键
     * @return 结果
     */
    @Override
    public int deleteSupplierBySupplierIds(Integer[] supplierIds)
    {
        return supplierMapper.deleteSupplierBySupplierIds(supplierIds);
    }

    /**
     * 删除供应商 信息
     *
     * @param supplierId 供应商 主键
     * @return 结果
     */
    @Override
    public int deleteSupplierBySupplierId(Integer supplierId)
    {
        return supplierMapper.deleteSupplierBySupplierId(supplierId);
    }

    @Override
    public int auditSupplier(SupplierVo supplierVo) {
        Supplier supplier=new Supplier();
        supplier.setSupplierId(supplierVo.getSupplierId());
        supplier.setAuditOpinion(supplierVo.getAuditOpinion());
        supplier.setAuditStatus(supplierVo.getAuditStatus());
        supplier.setAuditTime(new Date());
        supplier.setAuditPerson(SecurityUtils.getUsername());
        return supplierMapper.updateSupplier(supplier);
    }

    @Override
    public int approverSupplier(SupplierVo supplierVo) {
        Supplier supplier=new Supplier();
        supplier.setSupplierId(supplierVo.getSupplierId());
        supplier.setAuditStatus(supplierVo.getAuditStatus());
        supplier.setApproverOpinion(supplierVo.getApproverOpinion());
        supplier.setApproverTime(new Date());
        supplier.setApproverPerson(SecurityUtils.getUsername());
        return supplierMapper.updateSupplier(supplier);
    }

    @Override
    public List<Supplier> approverList() {
        return supplierMapper.approverList();
    }
}
